$(function(){
    var pagebtn = $("#getMorePage");
    var item_ul = $(".common-item");
    pagebtn.click(function(a) {
        a && a.preventDefault();
        var nextpage = $(this).attr('page'),pageParams = $(this).attr('param');
        $.ajax({type: "POST",url: "/ajax/"+pageParams,data: {page:nextpage},dataType: "json",beforeSend: function() {
            pagebtn.addClass("non").html("加载中&hellip;")
        },success: function(b) {
            if (b.status === 1) {
            	
                var i=0;
                b.items.forEach(function(item) {
                    if(b.type == "index") {
                        if(item.deal_title ==null){item.deal_title = item.sp_name}
                        var d = "<li><a href=\"/detail.php?id=" + item.goods_id + "&amp;sort=" + b.sort +"&amp;fr="+ b.fr +"\"><div class=\"pic\"><img src=\"";
                        if(i<2 && item.simg != ""){ d= d + item.simg + "\" original=\""} else { d= d+ b.imgHost + "img/lashou_index.png\" original=\""}
                        d = d + item.simg + "\" alt=\"" + item.short_title + "\"/></div><div class=\"item-name\"><div class=\"item-ico\">";
                        if(item.sortDate == 1) { d = d + "<span class=\"icon-new\"></span>"}
                        if(item.if_meet == 2) { d = d + "<span class=\"icon-freeres\"></span>"}
                        d = d + "</div><h2>" + item.deal_title + "</h2><h3>" + item.short_title;
                        
                        if(item.show_km){
                        	d = d + "</h3><div class=\"item-edit\"><p class=\"price\"><b>¥" + item.price + "</b><del>¥" + item.value + "</del></p><p class=\"num\">" + item.show_km + "</p></div></div></a></li>";
                        }else{
                        	d = d + "</h3><div class=\"item-edit\"><p class=\"price\"><b>¥" + item.price + "</b><del>¥" + item.value + "</del></p><p class=\"num\"><span></span>" + item.show_bought + "</p></div></div></a></li>";
                        }
                        
                    }
                    i++;
                    item_ul.append(d);
                });
                var n = b.items.length * (nextpage-1);
                $(".pic img:gt("+n+")").lazyload({
                    effect : "fadeIn",
                    threshold : 200,
                    forceInit:false
                });
                nextpage = parseInt(nextpage) + 1;
                pagebtn.attr("page", nextpage);
                nextpage <= b.pageCount ? pagebtn.removeClass('non').html('查看更多&hellip;') : pagebtn.addClass('non').html('没有更多产品').unbind("click")
            } else {
                pagebtn.addClass('non').html('没有更多产品').unbind("click");
            }
        },error: function() {
        }})
    })
})
